﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WebApplication2.Controllers.Domain.Entity;

namespace WebApplication2.Controllers.Domain
{
    public class DbInitializeHelper
    {
        public static void Initilizer()
        {
            using (var db = new Admin4000DbContext())
            {
                var dbExist = db.Database.EnsureCreated();

                var tet = db.Brands.Any();
                if (!tet)
                {
                    var abc = new Brand
                    {
                        BrandName = "honor 10x",
                        Description = "精彩生活，精彩世界"
                    };

                    db.SaveChanges();

                    db.Brands.Add(abc);

                    db.Products.AddRange(new Product[]{
                    new Product
                    {
                        ProductName = "Iphone 11",
                        ShortDesc = "给你不一样的视界",
                        FullDesc = "不止是Iphone",
                        BrandId = abc.Id
                    },new Product
                    {
                        ProductName = "Iphone 11 pro max",
                        ShortDesc = "给你不一样的视界",
                        FullDesc = "不止是Iphone",
                        BrandId = abc.Id
                    }
                });
                    db.SaveChanges();
                }
                
            }

        }
    }
}
